{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bikeshare数据集——线性回归分析\n",
    "\n",
    "我们将根据每天的天气信息数据训练和测试一个模型，并对模型的性能和预测能力进行测试。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1、导入必要的工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:07:15.319989Z",
     "start_time": "2019-12-08T07:07:15.315003Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np  # 矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "\n",
    "from sklearn.metrics import r2_score  #评价回归预测模型的性能\n",
    "\n",
    "import matplotlib.pyplot as plt   #画图\n",
    "import seaborn as sns\n",
    "\n",
    "# 图形出现在Notebook里而不是新窗口\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 读取数据\n",
    "做完特征工程后的数据，请先运行2. FE_BikeSharing_me.ipynb，得到文件FE_day.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:07:17.880140Z",
     "start_time": "2019-12-08T07:07:17.855209Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>season_1</th>\n",
       "      <th>season_2</th>\n",
       "      <th>season_3</th>\n",
       "      <th>season_4</th>\n",
       "      <th>mnth_1</th>\n",
       "      <th>mnth_2</th>\n",
       "      <th>mnth_3</th>\n",
       "      <th>mnth_4</th>\n",
       "      <th>mnth_5</th>\n",
       "      <th>...</th>\n",
       "      <th>weekday_5</th>\n",
       "      <th>weekday_6</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>holiday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>yr</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.355170</td>\n",
       "      <td>0.373517</td>\n",
       "      <td>0.828620</td>\n",
       "      <td>0.284606</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.379232</td>\n",
       "      <td>0.360541</td>\n",
       "      <td>0.715771</td>\n",
       "      <td>0.466215</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.171000</td>\n",
       "      <td>0.144830</td>\n",
       "      <td>0.449638</td>\n",
       "      <td>0.465740</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.175530</td>\n",
       "      <td>0.174649</td>\n",
       "      <td>0.607131</td>\n",
       "      <td>0.284297</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.209120</td>\n",
       "      <td>0.197158</td>\n",
       "      <td>0.449313</td>\n",
       "      <td>0.339143</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 35 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   instant  season_1  season_2  season_3  season_4  mnth_1  mnth_2  mnth_3  \\\n",
       "0        1         1         0         0         0       1       0       0   \n",
       "1        2         1         0         0         0       1       0       0   \n",
       "2        3         1         0         0         0       1       0       0   \n",
       "3        4         1         0         0         0       1       0       0   \n",
       "4        5         1         0         0         0       1       0       0   \n",
       "\n",
       "   mnth_4  mnth_5  ...  weekday_5  weekday_6      temp     atemp       hum  \\\n",
       "0       0       0  ...          0          1  0.355170  0.373517  0.828620   \n",
       "1       0       0  ...          0          0  0.379232  0.360541  0.715771   \n",
       "2       0       0  ...          0          0  0.171000  0.144830  0.449638   \n",
       "3       0       0  ...          0          0  0.175530  0.174649  0.607131   \n",
       "4       0       0  ...          0          0  0.209120  0.197158  0.449313   \n",
       "\n",
       "   windspeed  holiday  workingday  yr   cnt  \n",
       "0   0.284606        0           0   0   985  \n",
       "1   0.466215        0           0   0   801  \n",
       "2   0.465740        0           1   0  1349  \n",
       "3   0.284297        0           1   0  1562  \n",
       "4   0.339143        0           1   0  1600  \n",
       "\n",
       "[5 rows x 35 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# path to where the data lies\n",
    "#dpath = './data/'\n",
    "train = pd.read_csv(r\"D:\\AI\\machine_learning\\FE_day.csv\")\n",
    "\n",
    "#通过观察前5行，了解数据每列（特征）的概况\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:12:07.201791Z",
     "start_time": "2019-12-08T07:12:07.196807Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(731, 35)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:13:26.943452Z",
     "start_time": "2019-12-08T07:13:26.844704Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>season_1</th>\n",
       "      <th>season_2</th>\n",
       "      <th>season_3</th>\n",
       "      <th>season_4</th>\n",
       "      <th>mnth_1</th>\n",
       "      <th>mnth_2</th>\n",
       "      <th>mnth_3</th>\n",
       "      <th>mnth_4</th>\n",
       "      <th>mnth_5</th>\n",
       "      <th>...</th>\n",
       "      <th>weekday_5</th>\n",
       "      <th>weekday_6</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>holiday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>yr</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>count</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>731.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>mean</td>\n",
       "      <td>366.000000</td>\n",
       "      <td>0.247606</td>\n",
       "      <td>0.251710</td>\n",
       "      <td>0.257182</td>\n",
       "      <td>0.243502</td>\n",
       "      <td>0.084815</td>\n",
       "      <td>0.077975</td>\n",
       "      <td>0.084815</td>\n",
       "      <td>0.082079</td>\n",
       "      <td>0.084815</td>\n",
       "      <td>...</td>\n",
       "      <td>0.142271</td>\n",
       "      <td>0.143639</td>\n",
       "      <td>0.543594</td>\n",
       "      <td>0.518864</td>\n",
       "      <td>0.645649</td>\n",
       "      <td>0.346536</td>\n",
       "      <td>0.028728</td>\n",
       "      <td>0.683995</td>\n",
       "      <td>0.500684</td>\n",
       "      <td>4504.348837</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>std</td>\n",
       "      <td>211.165812</td>\n",
       "      <td>0.431917</td>\n",
       "      <td>0.434293</td>\n",
       "      <td>0.437380</td>\n",
       "      <td>0.429489</td>\n",
       "      <td>0.278797</td>\n",
       "      <td>0.268316</td>\n",
       "      <td>0.278797</td>\n",
       "      <td>0.274674</td>\n",
       "      <td>0.278797</td>\n",
       "      <td>...</td>\n",
       "      <td>0.349567</td>\n",
       "      <td>0.350963</td>\n",
       "      <td>0.228091</td>\n",
       "      <td>0.213909</td>\n",
       "      <td>0.146457</td>\n",
       "      <td>0.159766</td>\n",
       "      <td>0.167155</td>\n",
       "      <td>0.465233</td>\n",
       "      <td>0.500342</td>\n",
       "      <td>1937.211452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>min</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>22.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>25%</td>\n",
       "      <td>183.500000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.346343</td>\n",
       "      <td>0.339674</td>\n",
       "      <td>0.534704</td>\n",
       "      <td>0.232045</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3152.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>50%</td>\n",
       "      <td>366.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.547268</td>\n",
       "      <td>0.535113</td>\n",
       "      <td>0.644388</td>\n",
       "      <td>0.326928</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>4548.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>75%</td>\n",
       "      <td>548.500000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.743002</td>\n",
       "      <td>0.695083</td>\n",
       "      <td>0.750857</td>\n",
       "      <td>0.434622</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>5956.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>max</td>\n",
       "      <td>731.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>8714.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 35 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          instant    season_1    season_2    season_3    season_4      mnth_1  \\\n",
       "count  731.000000  731.000000  731.000000  731.000000  731.000000  731.000000   \n",
       "mean   366.000000    0.247606    0.251710    0.257182    0.243502    0.084815   \n",
       "std    211.165812    0.431917    0.434293    0.437380    0.429489    0.278797   \n",
       "min      1.000000    0.000000    0.000000    0.000000    0.000000    0.000000   \n",
       "25%    183.500000    0.000000    0.000000    0.000000    0.000000    0.000000   \n",
       "50%    366.000000    0.000000    0.000000    0.000000    0.000000    0.000000   \n",
       "75%    548.500000    0.000000    1.000000    1.000000    0.000000    0.000000   \n",
       "max    731.000000    1.000000    1.000000    1.000000    1.000000    1.000000   \n",
       "\n",
       "           mnth_2      mnth_3      mnth_4      mnth_5  ...   weekday_5  \\\n",
       "count  731.000000  731.000000  731.000000  731.000000  ...  731.000000   \n",
       "mean     0.077975    0.084815    0.082079    0.084815  ...    0.142271   \n",
       "std      0.268316    0.278797    0.274674    0.278797  ...    0.349567   \n",
       "min      0.000000    0.000000    0.000000    0.000000  ...    0.000000   \n",
       "25%      0.000000    0.000000    0.000000    0.000000  ...    0.000000   \n",
       "50%      0.000000    0.000000    0.000000    0.000000  ...    0.000000   \n",
       "75%      0.000000    0.000000    0.000000    0.000000  ...    0.000000   \n",
       "max      1.000000    1.000000    1.000000    1.000000  ...    1.000000   \n",
       "\n",
       "        weekday_6        temp       atemp         hum   windspeed     holiday  \\\n",
       "count  731.000000  731.000000  731.000000  731.000000  731.000000  731.000000   \n",
       "mean     0.143639    0.543594    0.518864    0.645649    0.346536    0.028728   \n",
       "std      0.350963    0.228091    0.213909    0.146457    0.159766    0.167155   \n",
       "min      0.000000    0.000000    0.000000    0.000000    0.000000    0.000000   \n",
       "25%      0.000000    0.346343    0.339674    0.534704    0.232045    0.000000   \n",
       "50%      0.000000    0.547268    0.535113    0.644388    0.326928    0.000000   \n",
       "75%      0.000000    0.743002    0.695083    0.750857    0.434622    0.000000   \n",
       "max      1.000000    1.000000    1.000000    1.000000    1.000000    1.000000   \n",
       "\n",
       "       workingday          yr          cnt  \n",
       "count  731.000000  731.000000   731.000000  \n",
       "mean     0.683995    0.500684  4504.348837  \n",
       "std      0.465233    0.500342  1937.211452  \n",
       "min      0.000000    0.000000    22.000000  \n",
       "25%      0.000000    0.000000  3152.000000  \n",
       "50%      1.000000    1.000000  4548.000000  \n",
       "75%      1.000000    1.000000  5956.000000  \n",
       "max      1.000000    1.000000  8714.000000  \n",
       "\n",
       "[8 rows x 35 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对数据值型特征，用常用统计量观察其分布\n",
    "train.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  数据基本信息\n",
    "样本数目、特征维数\n",
    "每个特征的类型、空值样本的数目、数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:13:08.532700Z",
     "start_time": "2019-12-08T07:13:08.514747Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method DataFrame.info of      instant  season_1  season_2  season_3  season_4  mnth_1  mnth_2  mnth_3  \\\n",
       "0          1         1         0         0         0       1       0       0   \n",
       "1          2         1         0         0         0       1       0       0   \n",
       "2          3         1         0         0         0       1       0       0   \n",
       "3          4         1         0         0         0       1       0       0   \n",
       "4          5         1         0         0         0       1       0       0   \n",
       "..       ...       ...       ...       ...       ...     ...     ...     ...   \n",
       "726      727         1         0         0         0       0       0       0   \n",
       "727      728         1         0         0         0       0       0       0   \n",
       "728      729         1         0         0         0       0       0       0   \n",
       "729      730         1         0         0         0       0       0       0   \n",
       "730      731         1         0         0         0       0       0       0   \n",
       "\n",
       "     mnth_4  mnth_5  ...  weekday_5  weekday_6      temp     atemp       hum  \\\n",
       "0         0       0  ...          0          1  0.355170  0.373517  0.828620   \n",
       "1         0       0  ...          0          0  0.379232  0.360541  0.715771   \n",
       "2         0       0  ...          0          0  0.171000  0.144830  0.449638   \n",
       "3         0       0  ...          0          0  0.175530  0.174649  0.607131   \n",
       "4         0       0  ...          0          0  0.209120  0.197158  0.449313   \n",
       "..      ...     ...  ...        ...        ...       ...       ...       ...   \n",
       "726       0       0  ...          0          0  0.243025  0.193709  0.671380   \n",
       "727       0       0  ...          1          0  0.241986  0.230993  0.606684   \n",
       "728       0       0  ...          0          1  0.241986  0.214393  0.774208   \n",
       "729       0       0  ...          0          0  0.245101  0.200348  0.497001   \n",
       "730       0       0  ...          0          0  0.195259  0.189567  0.593830   \n",
       "\n",
       "     windspeed  holiday  workingday  yr   cnt  \n",
       "0     0.284606        0           0   0   985  \n",
       "1     0.466215        0           0   0   801  \n",
       "2     0.465740        0           1   0  1349  \n",
       "3     0.284297        0           1   0  1562  \n",
       "4     0.339143        0           1   0  1600  \n",
       "..         ...      ...         ...  ..   ...  \n",
       "726   0.675656        0           1   1  2114  \n",
       "727   0.274350        0           1   1  3095  \n",
       "728   0.210260        0           0   1  1341  \n",
       "729   0.676936        0           0   1  1796  \n",
       "730   0.273062        0           1   1  2729  \n",
       "\n",
       "[731 rows x 35 columns]>"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.info"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:07:54.783405Z",
     "start_time": "2019-12-08T07:07:54.776423Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 从原始数据中分离输入特征x和输出y\n",
    "y = train[\"cnt\"]\n",
    "\n",
    "X = train.drop([\"cnt\"], axis = 1)\n",
    "\n",
    "#特征名称，用于后续显示权重系数对应的特征\n",
    "feat_names = X.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当数据量比较大时，可用train_test_split从训练集中分出一部分做校验集；\n",
    "样本数目较少时，建议用交叉验证。\n",
    "在线性回归中，留一交叉验证有简便计算方式。\n",
    "\n",
    "下面将训练数据分割成训练集和测试集，只是让大家对模型的训练误差、校验集上的测试误差估计、和测试集上的测试误差做个比较。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:07:58.431684Z",
     "start_time": "2019-12-08T07:07:58.423669Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(584, 34)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将数据分割训练数据与测试数据\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "# 随机采样20%的数据构建测试样本，其余作为训练样本\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=33, test_size=0.2)\n",
    "X_train.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、确定模型类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1 尝试缺省参数的线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:08:10.155275Z",
     "start_time": "2019-12-08T07:08:10.136328Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>33</td>\n",
       "      <td>yr</td>\n",
       "      <td>4550.708897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>27</td>\n",
       "      <td>temp</td>\n",
       "      <td>2654.792827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>mnth_9</td>\n",
       "      <td>1287.992360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>28</td>\n",
       "      <td>atemp</td>\n",
       "      <td>995.293778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>mnth_10</td>\n",
       "      <td>929.887649</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>weathersit_1</td>\n",
       "      <td>914.410909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>season_4</td>\n",
       "      <td>830.579518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>mnth_12</td>\n",
       "      <td>586.296405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>mnth_8</td>\n",
       "      <td>517.803038</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>weathersit_2</td>\n",
       "      <td>409.589079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>mnth_11</td>\n",
       "      <td>407.138803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>26</td>\n",
       "      <td>weekday_6</td>\n",
       "      <td>238.417312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>32</td>\n",
       "      <td>workingday</td>\n",
       "      <td>216.956549</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>mnth_6</td>\n",
       "      <td>189.797216</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>season_2</td>\n",
       "      <td>85.141889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>25</td>\n",
       "      <td>weekday_5</td>\n",
       "      <td>77.516263</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>23</td>\n",
       "      <td>weekday_3</td>\n",
       "      <td>66.464787</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>24</td>\n",
       "      <td>weekday_4</td>\n",
       "      <td>43.650546</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>mnth_5</td>\n",
       "      <td>5.009200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>instant</td>\n",
       "      <td>-6.919060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>22</td>\n",
       "      <td>weekday_2</td>\n",
       "      <td>-31.943212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>season_3</td>\n",
       "      <td>-130.807162</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>weekday_0</td>\n",
       "      <td>-191.612446</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>21</td>\n",
       "      <td>weekday_1</td>\n",
       "      <td>-202.493250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>mnth_7</td>\n",
       "      <td>-203.137582</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>31</td>\n",
       "      <td>holiday</td>\n",
       "      <td>-263.761415</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>mnth_4</td>\n",
       "      <td>-485.714239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>mnth_3</td>\n",
       "      <td>-541.439917</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>season_1</td>\n",
       "      <td>-784.914245</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>30</td>\n",
       "      <td>windspeed</td>\n",
       "      <td>-1174.845790</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>mnth_2</td>\n",
       "      <td>-1207.111892</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>29</td>\n",
       "      <td>hum</td>\n",
       "      <td>-1298.592138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>weathersit_3</td>\n",
       "      <td>-1323.999988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>mnth_1</td>\n",
       "      <td>-1486.521042</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         columns         coef\n",
       "33            yr  4550.708897\n",
       "27          temp  2654.792827\n",
       "13        mnth_9  1287.992360\n",
       "28         atemp   995.293778\n",
       "14       mnth_10   929.887649\n",
       "17  weathersit_1   914.410909\n",
       "4       season_4   830.579518\n",
       "16       mnth_12   586.296405\n",
       "12        mnth_8   517.803038\n",
       "18  weathersit_2   409.589079\n",
       "15       mnth_11   407.138803\n",
       "26     weekday_6   238.417312\n",
       "32    workingday   216.956549\n",
       "10        mnth_6   189.797216\n",
       "2       season_2    85.141889\n",
       "25     weekday_5    77.516263\n",
       "23     weekday_3    66.464787\n",
       "24     weekday_4    43.650546\n",
       "9         mnth_5     5.009200\n",
       "0        instant    -6.919060\n",
       "22     weekday_2   -31.943212\n",
       "3       season_3  -130.807162\n",
       "20     weekday_0  -191.612446\n",
       "21     weekday_1  -202.493250\n",
       "11        mnth_7  -203.137582\n",
       "31       holiday  -263.761415\n",
       "8         mnth_4  -485.714239\n",
       "7         mnth_3  -541.439917\n",
       "1       season_1  -784.914245\n",
       "30     windspeed -1174.845790\n",
       "6         mnth_2 -1207.111892\n",
       "29           hum -1298.592138\n",
       "19  weathersit_3 -1323.999988\n",
       "5         mnth_1 -1486.521042"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性回归\n",
    "#class sklearn.linear_model.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1)\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 1.使用默认配置初始化学习器实例\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 2.用训练数据训练模型参数\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "# 3. 用训练好的模型对测试集进行预测\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef\":list((lr.coef_.T))})\n",
    "fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.1.1 模型评价"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:08:56.136994Z",
     "start_time": "2019-12-08T07:08:56.131011Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is 0.8279474225980328\n",
      "The r2 score of LinearRegression on train is 0.8516480637403496\n"
     ]
    }
   ],
   "source": [
    "# 使用r2_score评价模型在测试集和训练集上的性能，并输出评估结果\n",
    "#测试集\n",
    "print ('The r2 score of LinearRegression on test is', r2_score(y_test, y_test_pred_lr))\n",
    "#训练集\n",
    "print ('The r2 score of LinearRegression on train is', r2_score(y_train, y_train_pred_lr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:09:01.203438Z",
     "start_time": "2019-12-08T07:09:00.965074Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeUAAAFsCAYAAADyj6FyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAfsElEQVR4nO3df5xddX3n8deHZEgsIQmB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yheeee65Px/nAAw9w++2388wzz3D44Ydz0UUXsXr1ahYtWsSdd95JS0sLH/rQh7j++us577zz+NKXvsS4cePYsmULs2fP5t577+XYY4/dVu8f/vCHfapHPUNZkgTA7373O6ZNm8bDDz/M61//et7+9rcDtVC+9dZbtwXqpk2bWLVqFSeddBKf+MQn+NSnPsXpp5/OSSedtN3+7rrrLmbNmsXW/7w566yz+MUvfrHLOmQmn/70p7njjjvYZ599ePTRR1m/fj2vfOUrt61zwgkncP755/Piiy9y5plnMm3atD4d75w5cxgxYgQjRoxg/PjxrF+/nqVLl7J8+XJOOOGEbW0yfnxtGI4bb7yRBQsWsHnzZtatW8fPf/7zbaF81lln9akOO/L0tSQJePma8po1a3jhhRe2XVPOTC699FJWrFjBihUrWL16NfPnz+ewww5j+fLlHHPMMVx66aV8/vOf32mf3f1b0PDhw3nppZe27f+FF14A4Prrr6ezs5Ply5ezYsUKDj744J3+1/fkk0/mjjvuYOLEiZx77rlce+21fTreESNGbJseNmwYmzdvJjOZN2/etmN98MEHaW9v51e/+hVXXnklS5cu5d5772XOnDnb1Wu//fbrUx12ZE9ZUpcavfu3v+8S1uAbM2YMV111FXPnzuWiiy7i1FNP5TOf+QznnHMOo0aN4tFHH6WlpYXNmzczbtw43ve+9zFq1Ciuueaa7fbzhje8gYsvvpiNGzcyevRobrrpJo477jigdh12+fLlvOc972HJkiW8+OKLQO0U+Pjx42lpaeH2229nzZqdv+VwzZo1TJw4kQsuuIBnn32We+65h/POO69fjn327NnMnTuXj33sY4wfP54nnniCZ555hqeffpr99tuPMWPGsH79en7wgx8wa9asfnnNeoayJBVosP/YmT59Oscddxw33HAD5557LitXrmTmzJlA7aas6667jtWrV/PJT36SffbZh5aWFr7xjW9st48JEybQ3t7OzJkzmTBhAscff/y2m6YuuOAC5s6dy4knnsjs2bO39TTPOecc3vnOd9LW1sa0adN43etet1Pdli1bxhVXXEFLSwujRo3qtqc8Z86cbeNOz5w5kw9/+MM9HveRRx7JF7/4RU455RReeuklWl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needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y_train - y_train_pred_lr, bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"Histogram of Residuals\") \n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "残差分布和高斯分布比较匹配."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:16:16.092874Z",
     "start_time": "2019-12-08T07:16:15.939285Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQCAYAAADcQn7hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO2de3wU1dn4v89ulmQTIBcIAlFEKi94QUWpIrS2gopFK9QL0tq3aG2t1V60FoXq70Vb+5aKFa3Wvlq19Q5eaLyLVrAWW1QwKKLS4p2A3MKGSxbYZJ/fHzMbNpuZ3dlkJ9mQ8/189pOdMzNnnhmYZ895znMRVcVgMBj8INDZAhgMhn0Xo2AMBoNvGAVjMBh8wygYg8HgG0bBGAwG3yjobAH8oG/fvjp48ODOFsNg6DYsX758s6pWprbvkwpm8ODBLFu2rLPFMBi6DSLyiVO7mSIZDAbfMArGYDD4hlEwBoPBN4yCMRgMvmEUjMFg8A2jYAwGg28YBWMwGJr56KOP+PGPf0wsFstJf0bBGAwGmpqauOmmmzj88MP5y1/+wsqVK3PSr1EwBkM35+233+b444/niiuuYNy4cbz77rscffTROel7n/TkNRgM3lBVzj//f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sTPoep2XqgKKk70Jmg7DgnmZgt/23CfP/Oe8wNhiD79gG3q0iMlREAsA3knb/Dbg0sSEiRzl08QLwQxEJ2sdUOByTzHas9KOGTsYoGENHcRXwPNay9tqk9kuBsbaR9l3g+w7n3gF8DrwtIm8BUzJc6wlgim38NUbeTsREUxsMBt8wIxiDweAbRsEYDAbfMArGYDD4hlEwBoPBN4yCMRgMvmEUjMFg8A2jYAwGg2/8fyNbOAqx0JJTAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 288x216 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#还可以观察预测值与真值的散点图\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, y_train_pred_lr)\n",
    "plt.plot([0,9000], [0,9000], '--k')   #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True cnt')\n",
    "plt.ylabel('Predicted cnt')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在y的真值大的部分预测效果还行"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2 正则化的线性回归（L2正则 --> 岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:18:29.411176Z",
     "start_time": "2019-12-08T07:18:29.396217Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is 0.8289740676988159\n",
      "The r2 score of RidgeCV on train is 0.849770002972564\n"
     ]
    }
   ],
   "source": [
    "#岭回归／L2正则\n",
    "#class sklearn.linear_model.RidgeCV(alphas=(0.1, 1.0, 10.0), fit_intercept=True, \n",
    "#                                  normalize=False, scoring=None, cv=None, gcv_mode=None, \n",
    "#                                  store_cv_values=False)\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "#1. 设置超参数（正则参数）范围\n",
    "alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "#n_alphas = 20\n",
    "#alphas = np.logspace(-5,2,n_alphas)\n",
    "\n",
    "#2. 生成一个RidgeCV实例\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)  \n",
    "\n",
    "#3. 模型训练\n",
    "ridge.fit(X_train, y_train)    \n",
    "\n",
    "#4. 预测\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print ('The r2 score of RidgeCV on test is', r2_score(y_test, y_test_pred_ridge))\n",
    "print ('The r2 score of RidgeCV on train is', r2_score(y_train, y_train_pred_ridge))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:20:13.475748Z",
     "start_time": "2019-12-08T07:20:13.344102Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZ4AAAEGCAYAAABVSfMhAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3de3Cc1Znn8e+jq+93Wb5bJjYmNgFiZGxsAyGAMWwSAgkJJDM2NjNMspnaJFOzO8ymKtQmW7XJzuxMFTsz2c0MMniTOJAAgSQQ2ziERL5h2WPAN7BBsi3buviCr1iy1M/+0UekLUvtlqzut9X6fapU3X3e8/Z5+pWtn/rto/eYuyMiIpIpeVEXICIifYuCR0REMkrBIyIiGaXgERGRjFLwiIhIRhVEXUC2GzVqlJeVlU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atwMEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 1.0\n"
     ]
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1)) \n",
    "\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "# plt.plot(np.log10(ridge.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', ridge.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:20:35.105878Z",
     "start_time": "2019-12-08T07:20:35.091937Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>33</td>\n",
       "      <td>yr</td>\n",
       "      <td>4550.708897</td>\n",
       "      <td>1504.623924</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>27</td>\n",
       "      <td>temp</td>\n",
       "      <td>2654.792827</td>\n",
       "      <td>1778.493414</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>mnth_9</td>\n",
       "      <td>1287.992360</td>\n",
       "      <td>678.352931</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>28</td>\n",
       "      <td>atemp</td>\n",
       "      <td>995.293778</td>\n",
       "      <td>1546.374034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>mnth_10</td>\n",
       "      <td>929.887649</td>\n",
       "      <td>84.873020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>weathersit_1</td>\n",
       "      <td>914.410909</td>\n",
       "      <td>914.843092</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>season_4</td>\n",
       "      <td>830.579518</td>\n",
       "      <td>767.205317</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>mnth_12</td>\n",
       "      <td>586.296405</td>\n",
       "      <td>-824.928596</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>mnth_8</td>\n",
       "      <td>517.803038</td>\n",
       "      <td>205.686009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>weathersit_2</td>\n",
       "      <td>409.589079</td>\n",
       "      <td>388.865215</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>mnth_11</td>\n",
       "      <td>407.138803</td>\n",
       "      <td>-725.828529</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>26</td>\n",
       "      <td>weekday_6</td>\n",
       "      <td>238.417312</td>\n",
       "      <td>227.515740</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>32</td>\n",
       "      <td>workingday</td>\n",
       "      <td>216.956549</td>\n",
       "      <td>212.558710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>mnth_6</td>\n",
       "      <td>189.797216</td>\n",
       "      <td>369.663154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>season_2</td>\n",
       "      <td>85.141889</td>\n",
       "      <td>110.998614</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>25</td>\n",
       "      <td>weekday_5</td>\n",
       "      <td>77.516263</td>\n",
       "      <td>81.396550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>23</td>\n",
       "      <td>weekday_3</td>\n",
       "      <td>66.464787</td>\n",
       "      <td>59.857933</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>24</td>\n",
       "      <td>weekday_4</td>\n",
       "      <td>43.650546</td>\n",
       "      <td>62.795850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>mnth_5</td>\n",
       "      <td>5.009200</td>\n",
       "      <td>387.713628</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>instant</td>\n",
       "      <td>-6.919060</td>\n",
       "      <td>1.417157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>22</td>\n",
       "      <td>weekday_2</td>\n",
       "      <td>-31.943212</td>\n",
       "      <td>-34.140080</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>season_3</td>\n",
       "      <td>-130.807162</td>\n",
       "      <td>-91.388275</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>weekday_0</td>\n",
       "      <td>-191.612446</td>\n",
       "      <td>-191.851510</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>21</td>\n",
       "      <td>weekday_1</td>\n",
       "      <td>-202.493250</td>\n",
       "      <td>-205.574484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>mnth_7</td>\n",
       "      <td>-203.137582</td>\n",
       "      <td>-242.548582</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>31</td>\n",
       "      <td>holiday</td>\n",
       "      <td>-263.761415</td>\n",
       "      <td>-248.222941</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>mnth_4</td>\n",
       "      <td>-485.714239</td>\n",
       "      <td>106.306513</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>mnth_3</td>\n",
       "      <td>-541.439917</td>\n",
       "      <td>298.550050</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>season_1</td>\n",
       "      <td>-784.914245</td>\n",
       "      <td>-786.815656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>30</td>\n",
       "      <td>windspeed</td>\n",
       "      <td>-1174.845790</td>\n",
       "      <td>-1087.773198</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>mnth_2</td>\n",
       "      <td>-1207.111892</td>\n",
       "      <td>-143.125249</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>29</td>\n",
       "      <td>hum</td>\n",
       "      <td>-1298.592138</td>\n",
       "      <td>-1142.397276</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>weathersit_3</td>\n",
       "      <td>-1323.999988</td>\n",
       "      <td>-1303.708307</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>mnth_1</td>\n",
       "      <td>-1486.521042</td>\n",
       "      <td>-194.714350</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         columns      coef_lr   coef_ridge\n",
       "33            yr  4550.708897  1504.623924\n",
       "27          temp  2654.792827  1778.493414\n",
       "13        mnth_9  1287.992360   678.352931\n",
       "28         atemp   995.293778  1546.374034\n",
       "14       mnth_10   929.887649    84.873020\n",
       "17  weathersit_1   914.410909   914.843092\n",
       "4       season_4   830.579518   767.205317\n",
       "16       mnth_12   586.296405  -824.928596\n",
       "12        mnth_8   517.803038   205.686009\n",
       "18  weathersit_2   409.589079   388.865215\n",
       "15       mnth_11   407.138803  -725.828529\n",
       "26     weekday_6   238.417312   227.515740\n",
       "32    workingday   216.956549   212.558710\n",
       "10        mnth_6   189.797216   369.663154\n",
       "2       season_2    85.141889   110.998614\n",
       "25     weekday_5    77.516263    81.396550\n",
       "23     weekday_3    66.464787    59.857933\n",
       "24     weekday_4    43.650546    62.795850\n",
       "9         mnth_5     5.009200   387.713628\n",
       "0        instant    -6.919060     1.417157\n",
       "22     weekday_2   -31.943212   -34.140080\n",
       "3       season_3  -130.807162   -91.388275\n",
       "20     weekday_0  -191.612446  -191.851510\n",
       "21     weekday_1  -202.493250  -205.574484\n",
       "11        mnth_7  -203.137582  -242.548582\n",
       "31       holiday  -263.761415  -248.222941\n",
       "8         mnth_4  -485.714239   106.306513\n",
       "7         mnth_3  -541.439917   298.550050\n",
       "1       season_1  -784.914245  -786.815656\n",
       "30     windspeed -1174.845790 -1087.773198\n",
       "6         mnth_2 -1207.111892  -143.125249\n",
       "29           hum -1298.592138 -1142.397276\n",
       "19  weathersit_3 -1323.999988 -1303.708307\n",
       "5         mnth_1 -1486.521042  -194.714350"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3 正则化的线性回归（L1正则 --> Lasso）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:22:24.258833Z",
     "start_time": "2019-12-08T07:22:24.209964Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.47062572154686677\n",
      "The r2 score of LassoCV on train is 0.4427527534180159\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\model_selection\\_split.py:1978: FutureWarning: The default value of cv will change from 3 to 5 in version 0.22. Specify it explicitly to silence this warning.\n",
      "  warnings.warn(CV_WARNING, FutureWarning)\n"
     ]
    }
   ],
   "source": [
    "#### Lasso／L1正则\n",
    "# class sklearn.linear_model.LassoCV(eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, \n",
    "#                                    normalize=False, precompute=’auto’, max_iter=1000, \n",
    "#                                    tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=1,\n",
    "#                                    positive=False, random_state=None, selection=’cyclic’)\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "#1. 设置超参数搜索范围\n",
    "#alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "\n",
    "#2. 生成学习器实例\n",
    "#lasso = LassoCV(alphas=alphas)\n",
    "\n",
    "#1. 设置超参数搜索范围\n",
    "#Lasso可以自动确定最大的alpha，所以另一种设置alpha的方式是设置最小的alpha值（eps） 和 超参数的数目（n_alphas），\n",
    "#然后LassoCV对最小值和最大值之间在log域上均匀取值n_alphas个\n",
    "# np.logspace(np.log10(alpha_max * eps), np.log10(alpha_max),num=n_alphas)[::-1]\n",
    "\n",
    "#2 生成LassoCV实例（默认超参数搜索范围）\n",
    "lasso = LassoCV()  \n",
    "\n",
    "#3. 训练（内含CV）\n",
    "lasso.fit(X_train, y_train)  \n",
    "\n",
    "#4. 测试\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print ('The r2 score of LassoCV on test is', r2_score(y_test, y_test_pred_lasso))\n",
    "print ('The r2 score of LassoCV on train is', r2_score(y_train, y_train_pred_lasso))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:22:26.902763Z",
     "start_time": "2019-12-08T07:22:26.771132Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAEGCAYAAAAjc0GqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deZhdVZ3v//enhswzKULIQIIJkjAlUIQgigqKAbsJ2tLG2w1pGuVexOtw7W7Bvr/mQdu+2narjVe40sJjoGkjMkikQToyiNpCUgmEEAKkgJAUmSpUZagMVamq7++PswoOZY0hZ6iqz+t5znP2/u6111o7Jznf7LXX2VsRgZmZWb6VFLoDZmY2MDkBmZlZQTgBmZlZQTgBmZlZQTgBmZlZQZQVugPFbvz48TFt2rRCd8PMrE9ZtWrVzoio6KqME1A3pk2bRlVVVaG7YWbWp0h6rbsyHoIzM7OCcAIyM7OCcAIyM7OCcAIyM7OCcAIyM7OCcAIyM7OCcAIyM7OCcAIyM7M/8L1fvcTvqnfmtA0nIDMze5vdBw7xL49soGpjfU7bcQIyM7O3eXpTPRFQOW1sTttxAjIzs7dZ9Vo9pSVizpQxOW0nZwlI0hBJKyStkbRO0g0pLknfkPSSpPWSPp8Vv1FStaRnJZ2eVddiSRvSa3FW/AxJa9M+N0pSio+TtDyVXy5pbHdtmJlZRtXGemZNHMnwwbm9XWguz4AagfMi4jRgDrBA0nzgL4ApwIkRMQtYmspfCMxMr6uAmyGTTIDrgbOAecD1bQkllbkqa78FKX4t8EhEzAQeSeudtmFmZhnNLa08s3kXlceNy3lbOUtAkdGQVsvTK4Crga9FRGsqtyOVWQjcnvZ7Eh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QdBSZs6JzUnIaSiYpnJOuHfWkroaIGHGE+vUEsDAi6o9EfWYd8RmQWWE9kB6KNwj4ekRsA4iIA5KuByYBm/LZoTRM+B0nH8s1nwGZmVlBeBKCmZkVhBOQmZkVhBOQmZkVhBOQmZkVhBOQmZkVxP8PUEhdGH2ElVEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 256.4697701374553\n"
     ]
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-08T07:22:30.823271Z",
     "start_time": "2019-12-08T07:22:30.802328Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>coef_lasso</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>33</td>\n",
       "      <td>yr</td>\n",
       "      <td>4550.708897</td>\n",
       "      <td>1504.623924</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>27</td>\n",
       "      <td>temp</td>\n",
       "      <td>2654.792827</td>\n",
       "      <td>1778.493414</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>mnth_9</td>\n",
       "      <td>1287.992360</td>\n",
       "      <td>678.352931</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>28</td>\n",
       "      <td>atemp</td>\n",
       "      <td>995.293778</td>\n",
       "      <td>1546.374034</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>mnth_10</td>\n",
       "      <td>929.887649</td>\n",
       "      <td>84.873020</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>weathersit_1</td>\n",
       "      <td>914.410909</td>\n",
       "      <td>914.843092</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>season_4</td>\n",
       "      <td>830.579518</td>\n",
       "      <td>767.205317</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>mnth_12</td>\n",
       "      <td>586.296405</td>\n",
       "      <td>-824.928596</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>mnth_8</td>\n",
       "      <td>517.803038</td>\n",
       "      <td>205.686009</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>weathersit_2</td>\n",
       "      <td>409.589079</td>\n",
       "      <td>388.865215</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>mnth_11</td>\n",
       "      <td>407.138803</td>\n",
       "      <td>-725.828529</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>26</td>\n",
       "      <td>weekday_6</td>\n",
       "      <td>238.417312</td>\n",
       "      <td>227.515740</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>32</td>\n",
       "      <td>workingday</td>\n",
       "      <td>216.956549</td>\n",
       "      <td>212.558710</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>mnth_6</td>\n",
       "      <td>189.797216</td>\n",
       "      <td>369.663154</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>season_2</td>\n",
       "      <td>85.141889</td>\n",
       "      <td>110.998614</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>25</td>\n",
       "      <td>weekday_5</td>\n",
       "      <td>77.516263</td>\n",
       "      <td>81.396550</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>23</td>\n",
       "      <td>weekday_3</td>\n",
       "      <td>66.464787</td>\n",
       "      <td>59.857933</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>24</td>\n",
       "      <td>weekday_4</td>\n",
       "      <td>43.650546</td>\n",
       "      <td>62.795850</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>mnth_5</td>\n",
       "      <td>5.009200</td>\n",
       "      <td>387.713628</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>instant</td>\n",
       "      <td>-6.919060</td>\n",
       "      <td>1.417157</td>\n",
       "      <td>5.456671</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>22</td>\n",
       "      <td>weekday_2</td>\n",
       "      <td>-31.943212</td>\n",
       "      <td>-34.140080</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>season_3</td>\n",
       "      <td>-130.807162</td>\n",
       "      <td>-91.388275</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>weekday_0</td>\n",
       "      <td>-191.612446</td>\n",
       "      <td>-191.851510</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>21</td>\n",
       "      <td>weekday_1</td>\n",
       "      <td>-202.493250</td>\n",
       "      <td>-205.574484</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>mnth_7</td>\n",
       "      <td>-203.137582</td>\n",
       "      <td>-242.548582</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>31</td>\n",
       "      <td>holiday</td>\n",
       "      <td>-263.761415</td>\n",
       "      <td>-248.222941</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>mnth_4</td>\n",
       "      <td>-485.714239</td>\n",
       "      <td>106.306513</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>mnth_3</td>\n",
       "      <td>-541.439917</td>\n",
       "      <td>298.550050</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>season_1</td>\n",
       "      <td>-784.914245</td>\n",
       "      <td>-786.815656</td>\n",
       "      <td>-341.190505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>30</td>\n",
       "      <td>windspeed</td>\n",
       "      <td>-1174.845790</td>\n",
       "      <td>-1087.773198</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>mnth_2</td>\n",
       "      <td>-1207.111892</td>\n",
       "      <td>-143.125249</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>29</td>\n",
       "      <td>hum</td>\n",
       "      <td>-1298.592138</td>\n",
       "      <td>-1142.397276</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>weathersit_3</td>\n",
       "      <td>-1323.999988</td>\n",
       "      <td>-1303.708307</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>mnth_1</td>\n",
       "      <td>-1486.521042</td>\n",
       "      <td>-194.714350</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         columns      coef_lr   coef_ridge  coef_lasso\n",
       "33            yr  4550.708897  1504.623924    0.000000\n",
       "27          temp  2654.792827  1778.493414    0.000000\n",
       "13        mnth_9  1287.992360   678.352931    0.000000\n",
       "28         atemp   995.293778  1546.374034    0.000000\n",
       "14       mnth_10   929.887649    84.873020    0.000000\n",
       "17  weathersit_1   914.410909   914.843092    0.000000\n",
       "4       season_4   830.579518   767.205317   -0.000000\n",
       "16       mnth_12   586.296405  -824.928596   -0.000000\n",
       "12        mnth_8   517.803038   205.686009    0.000000\n",
       "18  weathersit_2   409.589079   388.865215   -0.000000\n",
       "15       mnth_11   407.138803  -725.828529   -0.000000\n",
       "26     weekday_6   238.417312   227.515740   -0.000000\n",
       "32    workingday   216.956549   212.558710    0.000000\n",
       "10        mnth_6   189.797216   369.663154    0.000000\n",
       "2       season_2    85.141889   110.998614    0.000000\n",
       "25     weekday_5    77.516263    81.396550    0.000000\n",
       "23     weekday_3    66.464787    59.857933    0.000000\n",
       "24     weekday_4    43.650546    62.795850    0.000000\n",
       "9         mnth_5     5.009200   387.713628    0.000000\n",
       "0        instant    -6.919060     1.417157    5.456671\n",
       "22     weekday_2   -31.943212   -34.140080    0.000000\n",
       "3       season_3  -130.807162   -91.388275    0.000000\n",
       "20     weekday_0  -191.612446  -191.851510   -0.000000\n",
       "21     weekday_1  -202.493250  -205.574484   -0.000000\n",
       "11        mnth_7  -203.137582  -242.548582    0.000000\n",
       "31       holiday  -263.761415  -248.222941   -0.000000\n",
       "8         mnth_4  -485.714239   106.306513    0.000000\n",
       "7         mnth_3  -541.439917   298.550050    0.000000\n",
       "1       season_1  -784.914245  -786.815656 -341.190505\n",
       "30     windspeed -1174.845790 -1087.773198   -0.000000\n",
       "6         mnth_2 -1207.111892  -143.125249   -0.000000\n",
       "29           hum -1298.592138 -1142.397276   -0.000000\n",
       "19  weathersit_3 -1323.999988 -1303.708307   -0.000000\n",
       "5         mnth_1 -1486.521042  -194.714350   -0.000000"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T)), \"coef_lasso\":list((lasso.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
